import java.util.Stack;

public class Solution150 {
    public int evalRPN(String[] tokens) {
        Stack<Integer> stack=new Stack<>();
        for (String token : tokens) {
            if (token.equals("+")){
                int a=stack.pop();
                int b=stack.pop();
                stack.push(a+b);
            }else if (token.equals("-")){
                int a=stack.pop();
                int b=stack.pop();
                stack.push(b-a);
            }else if (token.equals("*")){
                int a=stack.pop();
                int b=stack.pop();
                stack.push(a*b);
            }else if (token.equals("/")){
                int a=stack.pop();
                int b=stack.pop();
                stack.push(b/a);
            }else{
                stack.push(Integer.parseInt(token));
            }
        }
        return stack.pop();
    }

    public static void main(String[] args) {
        System.out.println(new Solution150().evalRPN(new String[]{"2","1","+","3","*"}));
    }
}
